package com.ias.agdis_r.activity.setting;

import android.app.ActionBar;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.activity.BaseKeyActivity;
import com.ias.agdis_r.manager.DataBaseManager;
import com.ias.agdis_r.manager.EffectManager;
import com.ias.agdis_r.module.ParameterModel;

/**
 * Created by admin on 2016/3/29.
 */
public class KeyPressSettingActivity extends BaseKeyActivity {
    private ActionBar actionBar;
    private RadioGroup r1, rGroupTTS;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_keypress_setting);
        actionBar = getActionBar();
        initActionBar();
        r1 = (RadioGroup) findViewById(R.id.keypress_group);
        r1.setEnabled(true);
        rGroupTTS = (RadioGroup) findViewById(R.id.tts_group);
        rGroupTTS.setEnabled(true);
        showInfo();
    }

    private void initActionBar() {
        actionBar.setCustomView(LayoutInflater.from(this) .inflate(R.layout.actionbar_settings, null));
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setDisplayShowCustomEnabled(true);
        TextView title = (TextView) findViewById(R.id.txt_title);
        title.setText(R.string.setting_keyPress);
        ImageView back = (ImageView) findViewById(R.id.actionbar_settings_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void showInfo() {
        boolean isusing = DataBaseManager.getInstance().getBoolean(ParameterModel.T_KEYPRESS, ParameterModel.BACK_ISUSING);
        if (isusing) {
            ((RadioButton) r1.getChildAt(1)).setChecked(true);
        }
//        boolean isOpen = DataBaseManager.getInstance().getBoolean(ParameterModel.T_KEYPRESS, ParameterModel.TTS_ORDER);
//        if (isOpen) {
//            ((RadioButton)rGroupTTS.getChildAt(1)).setChecked(true);
//        }
    }

    @Override
    public void finish() {
        DataBaseManager.getInstance().insert(ParameterModel.T_KEYPRESS, ParameterModel.BACK_ISUSING, ((RadioButton) r1.getChildAt(1)).isChecked());
//        DataBaseManager.getInstance().insert(ParameterModel.T_KEYPRESS, ParameterModel.TTS_ORDER, ((RadioButton) rGroupTTS.getChildAt(1)).isChecked());
//        TTSManager.getInstance().initTTSOrder();    // 重新初始化语音播报是否顺序播放
        EffectManager.getInstance().ttsPlay(EffectManager.TTS_TYPE_UPTO, getString(R.string.save_config), false);
        super.finish();
    }
}
